Measure pixel width of a string?

Hello,

my idea is to set the width of Doors table columns to match the text inside the cells for a nice layout, i. e., run through the table, measure widest text inside and set the column width to maximum + epsilon. No problem, but how can I measure the width of a string in pixels? Most probably, font size comes into play here.

Thanks in advance, hgr00
hgr00 - Thu Jan 27 11:24:55 EST 2011

Re: Measure pixel width of a string?
llandale - Thu Jan 27 13:35:39 EST 2011

I doubt you want to adjust the table cell widths differently for each person, which may be needed since each person has her own display font style and size settings.

I suppose you could, however, have some ascii character lookup table that would return how "wide" a character is, on average, independant of font. Perhaps A "W" might me width 12, "w" width 10, and "i" width 3. Then send a function the string, have it evaluate each letting, and return the width.

You could perhaps develope the width of each character by perhaps putting 40 of them in a row and figuring out how wide that is, then deviding by 40.
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

You know, I may just do this as sometimes I want to pad a string with spaces before adding a tab, so information displayed in my reports lines up right.

  • Louie